package com.datalayer.testclasses;

import com.datalayer.annotations.*;
import com.datalayer.utils.AssociationType;

/**
 * Created with IntelliJ IDEA.
 * User: Georgiana.Scarlat
 * Date: 7/6/12
 * Time: 4:30 PM
 */
@SuppressWarnings("ALL")
@Entity(tableName = "ANGAJAT")
public class Angajat {

    String nume;
    int id;
    Functie functie;
    Departament departament;

    public Angajat() {
    }


    public Angajat(Departament departament, Functie functie, int id, String nume) {
        this.departament = departament;
        this.functie = functie;
        this.id = id;
        this.nume = nume;
    }


    @Direction("get")
    @Association(type = AssociationType.ONE2MANY, joins = {
            @Join(fieldName = "departament", insideName = "departament_fk", foreignName = "id"),
            @Join(fieldName = "departament", insideName = "dep_name_fk", foreignName = "nume")})
    public Departament getDepartament() {
        return departament;
    }

    @Direction("get")
    @Association(type = AssociationType.ONE2ONE_NONREFERENCED, joins = {
            @Join(fieldName = "functie", insideName = "functie_fk", foreignName = "id")})
    public Functie getFunctie() {
        return functie;
    }

    @Direction("get")
    @Constraint(constraintName = "primary key")
    @Attribute(fieldName = "id", attributeName = "id_angajat", type = "int")
    public int getId() {
        return id;
    }

    @Direction("get")
    @Attribute(fieldName = "nume", attributeName = "nume_angajat", type = "varchar(20)")
    public String getNume() {
        return nume;
    }

    @Direction("set")
    @Association(type = AssociationType.ONE2MANY, joins = {
            @Join(fieldName = "departament", insideName = "departament_fk", foreignName = "id"),
            @Join(fieldName = "departament", insideName = "dep_name_fk", foreignName = "nume")})
    public void setDepartament(Departament departament) {
        this.departament = departament;
    }

    @Direction("set")
    @Association(type = AssociationType.ONE2ONE_NONREFERENCED, joins = {
            @Join(fieldName = "functie", insideName = "functie_fk", foreignName = "id")})
    public void setFunctie(Functie functie) {
        this.functie = functie;
    }

    @Direction("set")
    @Attribute(fieldName = "id", attributeName = "id_angajat", type = "int")
    public void setId(int id) {
        this.id = id;
    }

    @Direction("set")
    @Attribute(fieldName = "nume", attributeName = "nume_angajat", type = "varchar(20)")
    public void setNume(String nume) {
        this.nume = nume;
    }


    @Override
    public String toString() {
        return "Angajat{" +
                "id=" + id +
                ", nume='" + nume + '\'' +
                ", functie=" + functie +
                ", departament=" + departament +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Angajat angajat = (Angajat) o;

        if (id != angajat.id) return false;
        if (nume != null ? !nume.equals(angajat.nume) : angajat.nume != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = nume != null ? nume.hashCode() : 0;
        result = 31 * result + id;
        return result;
    }

    public void foo() {
    }

    public void boo() {
    }
}
